<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
<script>
    window.addEventListener("load", function () {
        window.cookieconsent.initialise({
            "palette": {
                "popup": {
                    "background": "#494e52"
                },
                "button": {
                    "background": "#5197ad",
                    "text": "#ffffff"
                }
            },
            "revokable": false,
            "showLink": true,
            "position": "bottom-right",
            "type": "opt-out",
            "content": {
                "message": "This website uses cookies to ensure you get the best experience on our website.",
                "href": "/terms/"
            },
            onInitialise: function (status) {
                var type = this.options.type;
                var didConsent = this.hasConsented();
                if (type == 'opt-in' && didConsent) {
                    // enable cookies
                    setTracking(true);
                }
                if (type == 'opt-out' && !didConsent) {
                    // disable cookies
                    setTracking(false);
                }
            },
            onStatusChange: function (status, chosenBefore) {
                var type = this.options.type;
                var didConsent = this.hasConsented();
                if (type == 'opt-in' && didConsent) {
                    // enable cookies
                    setTracking(true);
                }
                if (type == 'opt-out' && !didConsent) {
                    // disable cookies
                    setTracking(false);
                }
            },
            onRevokeChoice: function () {
                var type = this.options.type;
                if (type == 'opt-in') {
                    // disable cookies
                    setTracking(false);
                }
                if (type == 'opt-out') {
                    // enable cookies
                    setTracking(true);
                }
            },
        })
    });

    // enables or disables google analytics
    setTracking = (track) => {
        if (track === true) {
            window['ga-disable-UA-131035631-1'] = false;
        }
        else {
            window['ga-disable-UA-131035631-1'] = true;
        }
    };
</script>